package com.wenwei.sharebox.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.wenwei.sharebox.R;
import com.wenwei.sharebox.base.BaseActivity;
import com.wenwei.sharebox.bean.GoodsInfoBean;
import com.wenwei.sharebox.net.ApiManager;
import com.wenwei.sharebox.net.BaseSubscriber;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/8/28.
 */
public class RepairActivity extends BaseActivity {
    @Bind(R.id.base_title)
    TextView baseTitle;
    @Bind(R.id.repair_et)
    EditText repairEt;
    @Bind(R.id.repair_tv)
    TextView repairTv;


    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_repair;
    }

    @Override
    protected void initView() {
        super.initView();
        baseTitle.setText("问题反馈");
        repairEt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (!repairEt.getText().toString().equals("")){
                    repairTv.setEnabled(true);
                    repairTv.setBackgroundResource(R.drawable.bc_share_select);
                }else {
                    repairTv.setEnabled(false);
                    repairTv.setBackgroundResource(R.drawable.bc_click_false);
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.base_back, R.id.repair_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.base_back:
                finish();
                break;
            case R.id.repair_tv:
                equipmentWarranty();
                break;
        }
    }

    @Override
    protected void init() {
        super.init();
        deviceNum = getIntent().getStringExtra("deviceCode");
    }

    private String deviceNum;
    private BaseSubscriber<GoodsInfoBean> eqSubscriber;
    private void equipmentWarranty(){
        eqSubscriber = new BaseSubscriber<GoodsInfoBean>(mContext) {
            @Override
            public void onSuccess(GoodsInfoBean o) {
                showToast("报修成功");
                goActivity(mContext,UserProvideActivity.class);
            }
        };
        ApiManager.getInstance().equipmentWarranty(eqSubscriber,deviceNum,repairEt.getText().toString());
    }
}
